﻿
@{
    ViewBag.Title = "动作列表";
}
@section scripts{
    <script type="text/javascript">
        var $tbGrid = {};
        $(function() {
            $.globalParas.datagrid.url = '@Url.Action("GetActionPage", "Permission", new {area = "Admin"})';
            $.globalParas.datagrid.columns = [
                [
                    { field: 'Name', title: '动作名称', width: 80, align: 'center' },
                    { field: 'Description', title: '动作描述', width: 140, align: 'center' },
                    { field: 'Url', title: 'URL地址', width: 100, align: 'center' },
                    { field: 'rArea', title: '区域名', width: 50, align: 'center' },
                    { field: 'rController', title: '控制器名', width: 60, align: 'center' },
                    { field: 'rAction', title: 'Action名', width: 80, align: 'center' },
                    { field: 'rMethod', title: '请求方式', width: 40, align: 'center' },
                ]
            ];
            $.globalParas.datagrid.idField = 'Id';
            $.globalParas.datagrid.loadFilter = function(response) {
                if (response.Statu === 1) {
                    return response.Data;
                } else
                    $.msgBoxObj.showMsgErr(response.Msg, true);
            };
            // 为'新增'按钮添加事件绑定
            $.globalParas.datagrid.bindBtnEvent('新增',
                function() {
                    $.globalParas.showComWindowObj({
                        title: '新增动作',
                        width: 450,
                        height: 500,
                        url: '@Url.Action("AddAction","Permission",new { area = "Admin" })',
                        callObject: $('#tbGrid')
                    });
                });
            // 为'修改'按钮添加事件绑定
            $.globalParas.datagrid.bindBtnEvent('修改',
                function() {
                    // 获取选定的数据
                    var rowData = $tbGrid.datagrid('getSelected');
                    // 判断是否选定了数据
                    if (rowData) {
                        $.globalParas.showComWindowObj({
                            title: '编辑用户',
                            width: 450,
                            height: 500,
                            url: '@Url.Action("EditAction", "Permission", new { area = "Admin" })' + '?Id=' + rowData.Id,
                            callObject: $('#tbGrid')
                        });
                    } else
                        window.top.$.msgBoxObj.showMsgErr('未选定任何行!');
                });
            // 添加删除按钮
            $.globalParas.datagrid.bindBtnEvent('删除',
                function() {
                    // 获取选定的数据
                    var rowData = $tbGrid.datagrid('getSelected');
                    // 判断是否选定了数据
                    if (rowData) {
                        // 用户重复确认是否删除
                        window.top.$.messager.confirm('确认',
                            '您确认要删除记录吗？删除后无法恢复！',
                            function(isOk) {
                                if (isOk) {
                                    // post请求DeleUser Action
                                    $.ajax({
                                        url: '@Url.Action("DeleteAction", "Permission", new {area = "Admin"})',
                                        type: 'Delete',
                                        data: { Id: rowData.Id},
                                        error: function() {
                                            // 提示网络错误
                                            $.msgBoxObj.showMsgErr('网络错误!');
                                        },
                                        success: function(response) {
                                            // 根据返回状态码 执行对应提示
                                            if (response.Statu === 1) {
                                                $.msgBoxObj.showMsgOk(response.Msg);
                                                $tbGrid.datagrid('reload');
                                            } else {
                                                $.msgBoxObj.showMsgErr(response.Msg);
                                            }
                                            return;
                                        }
                                    });
                                }
                            });
                    } else
                        window.top.$.msgBoxObj.showMsgErr('未选定任何行!', true);
                });
            // 初始化Grid控件
            $tbGrid = $("#tbGrid").datagrid($.globalParas.datagrid);
        });
    </script>
}
<table id="tbGrid"></table>